// pages/map/map.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mapInfo: {},
    markers: []
  },

  onReady() {
    // wx.createMapContext('1', component)
  },

  onLoad() {
    wx.getLocation({
      type: 'wgs84',
      isHighAccuracy: true,
      success: (res) => {
        const latitude = res.latitude
        const longitude = res.longitude
        let marker1 = {
          id: 1,
          latitude,
          longitude,
          iconPath: '11.jpg',
          width: '40px',
          height: '40px'
        }
        let {markers} = this.data 
        markers.push(marker1)

        this.setData({
          mapInfo: res,
          markers
        })
      }
     })
  },

  getLocation() {
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        
        this.setData({
          mapInfo: res
        })
      }
     })
  },

  chooseLocaion() {
    wx.chooseLocation({
      latitude: 0,
      success: (res) => {
        console.log(res);
        this.setData({
          mapInfo: res
        })
      }
    })
  },

  openLocation() {
    wx.getLocation({
      altitude: true,
      success: (res) => {
        const latitude = res.latitude
        const longitude = res.longitude
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          success: (res) => {
            console.log(res)
          }
        })
      }
    })
    
  }
})